/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode list=head;
       
        if(head==null) return head;
        while(list.next!=null){
            //元素相同直接跳过下一个。
            if(list.val==list.next.val){
                list.next=list.next.next;
            }else{//元素不同指向下一个              
                list=list.next;
            }
        }
        return head;
    }
}